preserve 

replace PTC = . if nonRecon == 1

collapse (sum) PTC APTC trueUp excessAPTC repayLimit APTC_repay safeHarbor nonReconTrueUp nonReconAPTC_repay APTC_comp nonFilerAPTC [pw = wt], by(flpdyr) fast

local day = day(date(c(current_date), "DMY"))
if(`day' < 10) local day = ".0" + "`day'"
else local day = "." + "`day'"
local month = month(date(c(current_date), "DMY"))
if(`month' < 10) local month = ".0"+"`month'"
else local month = "." + "`month'"
local year = year(date(c(current_date), "DMY"))

capture mkdir "$workingDir/output/Figure_2/old"
capture copy "$workingDir/output/Figure_2/Figure_2_total_PTC_components.xlsx" "$workingDir/output/Figure_2/old/`year'`month'`day'_Figure_2_total_PTC_components.xlsx"

order flpdyr PTC APTC trueUp excessAPTC repayLimit APTC_repay safeHarbor nonReconTrueUp nonReconAPTC_repay APTC_comp nonFilerAPTC
sort flpdyr
mkmat flpdyr PTC APTC trueUp excessAPTC repayLimit APTC_repay safeHarbor nonReconTrueUp nonReconAPTC_repay APTC_comp nonFilerAPTC, matrix(output)
putexcel set "$workingDir/output/Figure_2/Figure_2_total_PTC_components.xlsx", sheet("data") modify
putexcel A1 = matrix(output), colnames
putexcel close

restore
